package com.emapp.lccode.adapter

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.emapp.lccode.activity.DeviceAddKtActivity
import com.emapp.lccode.activity.DeviceKtActivity
import com.emapp.lccode.activity.HomeTypeKTActivity
import com.emapp.lccode.activity.MyOrderKtActivity
import com.emapp.lccode.activity.ProjectAddKtActivity
import com.emapp.lccode.activity.ProjectGridListActivity
import com.emapp.lccode.activity.ProjectListActivity
import com.emapp.lccode.activity.ProjectMapActivity
import com.emapp.lccode.activity.XunjianListActivity
import com.emapp.lccode.bean.HomeType
import com.emapp.lccode.databinding.ListitemHomeTypeBinding
import com.emapp.lccode.utils.clickNoRepeat
import com.emapp.lccode.utils.toStartActivity
import com.emapp.lccode.utils.toast

class HomeTypeKTAdapter :BaseQuickAdapter<HomeType, HomeTypeKTAdapter.VH>() {

    // 自定义ViewHolder类
    class VH(
        parent: ViewGroup,
        val binding: ListitemHomeTypeBinding = ListitemHomeTypeBinding.inflate(
            LayoutInflater.from(parent.context), parent, false
        ),
    ) : RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
        // 返回一个 ViewHolder
        return VH(parent)
    }

    override fun onBindViewHolder(holder: VH, position: Int, item: HomeType?) {
        // 设置item数据
        holder.binding.tvName.text= item!!.name
        holder.binding.ivImage.setImageResource(item.img)
        holder.binding.root.clickNoRepeat {
            when (item.name) {
                "全部" -> {
                    toStartActivity(HomeTypeKTActivity::class.java)
                }

                "工单管理" -> {
                    toStartActivity(MyOrderKtActivity::class.java)
                }

                "设施设备管理" -> {
                    toStartActivity(DeviceKtActivity::class.java)
                }
                "项目地图" -> {
                    toStartActivity(ProjectListActivity::class.java)
                }
                "我的工程" -> {
                    toStartActivity(ProjectGridListActivity::class.java)
                }
                "巡检日志" -> {
                    toStartActivity(XunjianListActivity::class.java)
                }
                else ->{
                    //"暂未开放".toast()
                }
            }
        }
    }


}